//
// Created by Zhangwj on 2023/9/26.
//

#include "VarDefNode.h"

std::unique_ptr<VarDefNode> VarDefNode::VarDefParser(Parser &parser) {
    //VarDef → Ident { '[' ConstExp ']' } | Ident { '[' ConstExp ']' } '=' InitVal
    std::unique_ptr<VarDefNode> varDefNode = std::make_unique<VarDefNode>();
    varDefNode->Ident = IdentNode::IdentParser(parser);
    while (parser.getLexType(0) == LexType::LBRACK) {
        parser.next();
        varDefNode->ConstExps.push_back(ConstExpNode::ConstExpParser(parser));
        if (parser.getLexType(0) == LexType::RBRACK) {
            parser.next();
        }
    }
    if (parser.getLexType(0) == LexType::ASSIGN) {
        parser.next();
        varDefNode->InitVal = InitValNode::InitValParser(parser);
    }
    return varDefNode;
}
